package com.his.dao.jpa;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import com.his.pojos.jpa.HisOperationdetail;
import com.his.vo.DetailVO;
import com.his.vo.MxjOperationParticularsVO;

public interface MxjOperationDetailDAO extends CrudRepository<HisOperationdetail, Long> {
	@Query("select max(ssmxNo) from HisOperationdetail")
	public String findmaxId();
	
	@Query("select "
			+ "new com.his.vo.DetailVO( o.ssNo, o.ssName,  e.ygName,  otr.sssName,  od.ssStarttime,  o.remarks) "
			+ "from HisOperation o,HisOperationdetail od,HisEmployee e,HisOperationRoom otr "
			+ "where od.ssNo=o.ssNo and od.ygNo=e.ygNo and od.sssNo=otr.sssNo"
			+ " order by o.ssNo desc")
	public List<DetailVO> findByPage(Pageable pageable);
	
	@Query("from HisOperationdetail od where od.ssNo=:ssNo")
	public HisOperationdetail findAssmx(@Param("ssNo")BigDecimal ssNo);
	
	@Query("select ssmxNo from HisOperationdetail where ssmxNo=:ssmxNo")
	public String inspectdetailNo(@Param("ssmxNo")long ssmxNo);
	
	@Query("select "
			  +"new com.his.vo.MxjOperationParticularsVO(ot.ssName, e.ygName, mc.brName,  mc.brAge, mc.brSex, otr.sssName, otg.djName, ott.lxName, otd.ssStarttime, otd.ssEndtime, ot.ssCost, ot.remarks) "
		      +"from HisOperationdetail otd, HisOperation ot, HisOperationType ott, "
		      +"HisOperationGrade otg, HisMedicalCard mc, HisEmployee e, HisOperationRoom otr "
		      +"where "
		      +"otd.ssNo=ot.ssNo and ot.ylkNo=mc.ylkNo and ot.ssType=ott.lxNo and ot.ssGrade=otg.djNo and " 
		      +"otd.sssNo=otr.sssNo and otd.ygNo=e.ygNo and ot.ssNo=:ssNo")
	public MxjOperationParticularsVO findAVO(@Param("ssNo")long ssNo);
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
